#include <stdio.h>
#include <stdlib.h>

struct Student
{
	int idnum;
	char name[20];
	double grade;
};

int main()
{
	struct Student info;
	FILE *input,*output;
	input = freopen("student.txt","r",stdin);
	if(input==NULL)
	{
		printf("wrong.\n"); 
	}
	while(scanf("%i%s%lf",&info.idnum,info.name,&info.grade) != EOF) 
	{
		printf("idnum:%03i name:%s grade:%.2lf\n",info.idnum,info.name,info.grade);
	}
	fclose(input);
	int tmp = 1;
	freopen("CON", "r", stdin);
	while(1)
	{
		printf("To add new student information?Press 1 to add, press 0 to quit.\n");
		scanf("%i",&tmp);
		if(tmp == 0)
		{
			break;
		}
		printf("Now you can input the idnum, name and grade.\n");
		scanf("%i",&info.idnum);
		scanf("%s",info.name);
		scanf("%lf",&info.grade);
		printf("Finished.\n");
		output = freopen("student.txt","a",stdout);
		{
			printf("%i %s %.2lf\n",info.idnum,info.name,info.grade);
		}
		fclose(output);
		freopen("CON", "w", stdout);
	}
	return 0;
} 